﻿using System.ServiceModel;
using SpectrumAnalyser.Common.Logs.Attributes;
using SpectrumAnalyser.Data.Common.Contracts;
using SpectrumAnalyser.Data.DataBase.Contracts;
using SpectrumAnalyser.ModelObjects;
using SpectrumAnalyser.Services.Common.Attributes;
using SpectrumAnalyser.Services.ExpertiseResultStorageServiceContracts;

namespace SpectrumAnalyser.Services.ExpertiseResultStorageService.Services
{
    [Log]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class ExpertiseStorageService : IExpertiseStorageServiceContract, IWithRepositoryFactory
    {
        [RequireRepositoryFactory]
        [RequiresInstanceName]
        public void Ping()
        {
            using (ITransaction transaction = RepositoryFactory.BeginTransaction())
            {
                var t = RepositoryFactory.Create<ITestRepositoryContract>();

                var r = t.Save(new Foo
                    {
                        Id = 0,
                        Name = "Tom22"
                    });
                var r1 = t.Save(new Foo
                {
                    Id = 0,
                    Name = "Tom222"
                });

                transaction.Commit();
            }
        }

        public string Instance { get; set; }

        public IRepositoryFactory RepositoryFactory { get; set; }
    }
}
